package cn.chen.数据结构.计算面积;

import java.util.Scanner;

public class Test {

    public static void main(String[] args){

        Scanner sc=new Scanner(System.in);
        while(true){

            System.out.println("请选择你要进行的操作（序号）：");
            System.out.println("1、计算圆面积");
            System.out.println("2、计算圆周长");
            System.out.println("3、计算长方形面积");
            System.out.println("4、计算长方形周长");
            System.out.println("5、退出程序");
            String index = sc.next();
            switch (index){

                case "1":
                    System.out.println("请输入圆半径：");
                    String radiusStr = sc.next();
                    try {
                        int radius = Integer.parseInt(radiusStr);   // 如果出现异常，就会跳转到catch中。
                        double area = new Round(radius).area();
                        System.out.println("圆的面积为："+area);
                    }catch (Exception e){
//                        System.out.println(e.getMessage()); // 这里是输出的异常信息。如果你不想输出异常信息，那么就
                        System.out.println("你输入的数据有误，请重新输入：");  // 可以输出这句话，让用户可以清晰的了解是怎么一回事
                    }
                    break;
                case "2":
                    System.out.println("请输入圆半径：");
                    String radiusStr1 = sc.next();
                    try {
                        int radius = Integer.parseInt(radiusStr1);
                        double area = new Round(radius).perimeter();
                        System.out.println("圆的面积为："+area);
                    }catch (Exception e){
                        System.out.println(e.getMessage());
                    }
                    break;
                case "3":
                    System.out.println("请输入长方形的高：");
                    String heightStr = sc.next();
                    int height=0;
                    try {
                        height = Integer.parseInt(heightStr);
                    }
                    catch (Exception e){
                        System.out.println(e.getMessage());
                    }
                    System.out.println("请输入长方形的宽：");
                    String widthStr = sc.next();
                    try {
                        int width = Integer.parseInt(widthStr);
                        double area = new Rectangle(width, height).area();
                        System.out.println("长方形的面积："+area);
                    }
                    catch (Exception e){
                        System.out.println(e.getMessage());
                    }
                    break;
                case "4":
                    System.out.println("请输入长方形的高：");
                    String heightStr1 = sc.next();
                    int height1=0;
                    try {
                        height = Integer.parseInt(heightStr1);
                    }
                    catch (Exception e){
                        System.out.println(e.getMessage());
                    }
                    System.out.println("请输入长方形的宽：");
                    String widthStr1 = sc.next();
                    try {
                        int width = Integer.parseInt(widthStr1);
                        double area = new Rectangle(width, height1).perimeter();
                        System.out.println("长方形的面积："+area);
                    }
                    catch (Exception e){
                        System.out.println(e.getMessage());
                    }
                    break;
                case "5":
                    System.exit(0);
                    break;
                    default:
                        System.out.println("输入错误~请重新输入");
                        break;
            }
        }
    }
}
